//
//  currentView.m
//  qulvyou
//
//  Created by mmyy on 15/10/22.
//  Copyright (c) 2015年 mmyy. All rights reserved.
//

#import "currentView.h"

@implementation currentView


+(UIView *)createViewToFreame:(CGRect)rect withData:(CurrentDayItems *)items
{
    UIView *bgView = [[UIView alloc] initWithFrame:rect];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 5;
    bgView.layer.masksToBounds = YES;
    CGFloat imageW = rect.size.width;
//    CGFloat imageH = [items.cover_image_height floatValue] / ([items.cover_image_width floatValue] / imageW);
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageW, 100)];
    imageView.backgroundColor = [UIColor orangeColor];
    [imageView setImageWithURL:[NSURL URLWithString:items.cover_image] placeholderImage:[UIImage imageNamed:@"define"]];
    [bgView addSubview:imageView];
    
    UILabel *text = [UILabel new];
    text.text = items.text;
    text.textColor = [UIColor blackColor];
    text.backgroundColor = [UIColor clearColor];
    text.font = [UIFont systemFontOfSize:12];
    text.lineBreakMode = NSLineBreakByWordWrapping;
    text.numberOfLines = 2;
    [bgView addSubview:text];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.bottom).offset(5);
        make.left.equalTo(bgView.left).offset(10);
        make.right.equalTo(bgView.right).offset(-10);
        make.height.equalTo(30);
    }];
    
    UIImageView *avatar_l = [UIImageView new];
    [avatar_l setImageWithURL:[NSURL URLWithString:items.avatar_l]];
    avatar_l.layer.cornerRadius = 15;
    avatar_l.layer.masksToBounds = YES;
    [bgView addSubview:avatar_l];
    [avatar_l mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(text.bottom).offset(3);
        make.left.equalTo(bgView.left).offset(10);
        make.width.equalTo(30);
        make.height.equalTo(30);
    }];
    
    UILabel *name = [UILabel new];
    name.text = items.name;
    name.font = [UIFont systemFontOfSize:13];
    name.adjustsFontSizeToFitWidth = YES;
    name.backgroundColor = [UIColor clearColor];
    name.textColor = [UIColor darkGrayColor];
    [bgView addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avatar_l.right).offset(10);
        make.right.equalTo(bgView.right).offset(-10);
        make.height.equalTo(15);
        make.top.equalTo(text.bottom).offset(12.5);
    }];
    return bgView;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
